﻿/**
 * Created by Administrator on 2017/6/3.
 */

window.onload = function(){
    var time = null;
    var obtn = document.getElementById('top_btn');
    window.onscroll = function(){
        var osTop = document.documentElement.scrollTop || document.body.scrollTop;
        if(osTop >= 100){
            obtn.style.display = 'block';
        }else{
            obtn.style.display = 'none';
        }
    };
    obtn.onclick = function(){

        time = setInterval(function(){
            var osTop = document.documentElement.scrollTop || document.body.scrollTop;
            var ispeed = Math.floor(-osTop/6);
            document.documentElement.scrollTop = document.body.scrollTop = osTop + ispeed;

            if(osTop === 0){
                clearInterval(time);
            }
        },30);
    }
};